const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    room_list: [],
  },
  onLoad: function () {
    var that = this
    let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
    const token = extConfig.appid;
    that.setData({
      token: token
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function (options) {
    wx.showLoading({
      title: '加载中……',
    })
    this.getGoodsList();
  },
  getGoodsList: function () {
    var that = this
    wx.request({
      url: 'https://www.58zltc.com/api.php/Hotel/roomList/openid/' + app.globalData.openid + '?token=' + that.data.token,
      success: res => {
        this.setData({
          room_list: res.data
        })
        wx.hideLoading()
      }
    })
  },
  editGood: function (e) {
    wx.navigateTo({
      url: 'add?type=edit&id=' + e.target.dataset.id,
    })
  },
  delGood: function (e) {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '确定要删除该房型？',
      success: function (res) {
        if (res.confirm) {
          wx.showLoading({
            title: '删除中……',
          })
          wx.request({
            url: 'https://www.58zltc.com/api.php/Hotel/roomDel/openid/' + app.globalData.openid + '&id=' + e.target.dataset.id + '?token=' + that.data.token,
            success: res => {
              if (res.data.err_code > 0) {
                wx.showToast({
                  title: res.data.err_msg,
                })
              } else {
                wx.showToast({
                  title: res.data.err_msg,
                  icon: 'success'
                })
                that.getGoodsList();
              }
            }
          })
        }
      }
    })
  },
  backto: function () {
    wx.navigateBack({})
  }
})